package com.gcc.crudmysqldemotext.service;

import com.gcc.crudmysqldemotext.model.Employee;
import com.gcc.crudmysqldemotext.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class EmployeeService {
    @Autowired
    private EmployeeRepository employeeRepository;
    public Employee save(Employee employee) {
        return employeeRepository.save(employee);
    }
    public List<Employee> findAll(){
        return employeeRepository.findAll();
    }
    public Optional<Employee> findById(Long id) {
        return employeeRepository.findById(id);
    }

    public boolean deleteById(Long id) {
        if(employeeRepository.existsById(id)){
            employeeRepository.deleteById(id);
            return true;
        }
        return false;
    }
}
